package com.oa.service.impl;

import com.oa.vo.Page;
import com.oa.pojo.Clz;
import com.oa.mapper.ClzMapper;
import com.oa.service.ClzService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClzServiceImpl implements ClzService {

    @Autowired
    ClzMapper clzMapper;

    @Override
    public void addClz(Clz clz) {
        clzMapper.addClz(clz);
    }

    @Override
    public void delClz(Integer classId) {
        clzMapper.delClz(classId);
    }

    @Override
    public void updateClz(Clz clz) {
        clzMapper.updateClz(clz);
    }

    @Override
    public List<Clz> getClzList() {
        return clzMapper.getClzList();
    }

    @Override
    public Page getClzPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Clz> clzList = clzMapper.getClzList();
        Page page = new Page();
        PageInfo<Clz> pageInfo = new PageInfo<>(clzList);
        page.setPageCount(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());
        page.setObject(pageInfo.getList());
        return page;
    }

    @Override
    public Clz getClz(Integer classId) {
        return clzMapper.getClz(classId);
    }
}
